﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;
using DTO;

namespace GUI
{
    public partial class frmTraCuuHoaDon : Form
    {
        public frmTraCuuHoaDon()
        {
            InitializeComponent();
        }

        private void frmTraCuuHoaDon_Load(object sender, EventArgs e)
        {
            hienthidanhsach();
            hienthimahoadon();
            hienthitenkhachhang();
        }
        public void hienthimahoadon()
        {
            List<HoaDonDTO> ds;
            HoaDonBUS bus = new HoaDonBUS();
            ds = bus.LayDanhSachHoaDon();
            this.cbmahoadon.Items.Clear();
            for (int i = 0; i <= ds.Count - 1; i++)
            {
                cbmahoadon.Items.Add(ds[i].MaHoaDon);
            }
            this.cbmahoadon.ValueMember = "MaHoaDon";
            this.cbmahoadon.DisplayMember = "MaHoaDon";
        }
        public void hienthitenkhachhang()
        {
            List<KhachHangDTO> ds;
            KhachHangBUS bus = new KhachHangBUS();
            ds = bus.GetKhachHangAll();
            this.cbmakhachhang.Items.Clear();
            this.cbmakhachhang.ValueMember = "MaKhachHang";
            this.cbmakhachhang.DisplayMember = "TenKhachHang";
            for (int i = 0; i <= ds.Count - 1; i++)
            {
                cbmakhachhang.Items.Add(ds[i].TenKhachHang);
            }

        }

        public void hienthidanhsach()
        {
            List<HoaDonDTO> ds;
            HoaDonBUS bus = new HoaDonBUS();
            ds = bus.LayDanhSachHoaDon();
            this.dgvdshoadon.Rows.Clear();
            for (int i = 0; i <= ds.Count - 1; i++)
            {
                this.dgvdshoadon.Rows.Add(ds[i].MaHoaDon, ds[i].MaKhachHang, ds[i].NgayLap, ds[i].NgayGiao, ds[i].ThanhTien);
            }
        }

        private void bttracuu_Click(object sender, EventArgs e)
        {
            string mahoadon = this.cbmahoadon.Text;
            string tenkhachhang = cbmakhachhang.Text;

            DateTime tungay = dtpTuNgay.Value;
            DateTime denngay = dtpDenNgay.Value;


            HoaDonBUS bus = new HoaDonBUS();
            List<HoaDonDTO> ds = bus.Tra_cuu_hoa_don(mahoadon, tenkhachhang, tungay, denngay);

            dgvdshoadon.Rows.Clear();
            for (int i = 0; i <= ds.Count - 1; i++)
            {
                this.dgvdshoadon.Rows.Add(ds[i].MaHoaDon, ds[i].MaKhachHang, ds[i].NgayLap, ds[i].NgayGiao, ds[i].ThanhTien);
            }
        }

        private void btnlammoi_Click(object sender, EventArgs e)
        {
            cbmahoadon.Text = "";
            cbmakhachhang.Text = "";
        }

        private void btnexit_Click(object sender, EventArgs e)
        {
            //DialogResult dlr = MessageBox.Show("Bạn muốn thoát khỏi chương trình?", "Warnning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            //if (dlr == DialogResult.Yes)
            //    this.Close();
            Close();
        }
    }
}
